/*
 * @Date: 2020-07-16 14:47:48
 * @LastEditTime: 2020-07-16 14:52:10
 * @Description: 浏览器存储
 * @FilePath: \vue\src\common\utilStorage.js
 */

// 存储localStorage
const setStore = (name, content) => {
    if (!name) return
    if (typeof content !== 'string') {
        content = JSON.stringify(content)
    }
    window.localStorage.setItem(name, content)
}

// 获取localStorage
const getStore = name => {
    if (!name) return
    return window.localStorage.getItem(name)
}

// 删除localStorage
const removeStore = name => {
    if (!name) return
    window.localStorage.removeItem(name)
}

// 存储sessionStorage
const setSessionStore = (name, content) => {
    if (!name) return
    if (typeof content !== 'string') {
        content = JSON.stringify(content)
    }
    window.sessionStorage.setItem(name, content)
}

// 获取sessionStorage
const getSessionStore = name => {
    if (!name) return
    return window.sessionStorage.getItem(name)
}

// 删除sessionStorage
const removeSessionStore = name => {
    if (!name) return
    window.sessionStorage.removeItem(name)
}

export {
    setStore,
    getStore,
    removeStore,
    setSessionStore,
    getSessionStore,
    removeSessionStore
}